home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: calloc help needed
- Date: 16 Feb 1996 22:15:22 GMT
- Organization: OpenVision
- Message-ID: <4g2vlq$n4k@spanky.pls.ov.com>
- References: <1996Feb15.125431.7751@leeds.ac.uk>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 7751@leeds.ac.uk, csyamc@scs.leeds.ac.uk (A M Casey) writes:
- >I'm trying to allocate enough memory for an array of strings, defined as
- >char * MyArray[20].
- >the only manual entry I have for calloc says that it needs two values, the
- >number of elements, and the size of each, but how do I actually use it?
- >
- >MyArray = calloc(20,50);
- >
- >doesnt work, as far as I can tell calloc returns an int.
- >
- >ANy help would be greatly appreciated
- >
- >ANdy
-
-
- Like malloc(), calloc() returns a pointer to a memory area of the size
- that you specified. How you use that pointer is strictly up to you.
-
- One side effect of calloc() is that the memory set aside is initialized to
- all zeroes.
-
- It's clear that you need to examine your manual entry more carefully. It
- should have said something like:
-
- void *calloc(unsigned nelem, unsigned elsize);
-
- From the above you can tell that the function returns a pointer of undetermined
- type. Further, the text in my manual (for malloc, calloc, realloc) says
- (in part):
-
- Each of the allocation routines returns a pointer to space
- suitably aligned for storage of any type of object. Each
- returns a NULL pointer if the request cannot be completed
- (see DIAGNOSTICS).
-
- Fletcher.Glenn@ov.com
-
-